package com.wangshouyu.plugins.mvc.config;

import com.wangshouyu.plugins.mvc.advice.ResponseBodyResultAdvice;
import com.wangshouyu.plugins.mvc.handler.DefaultResponseBodyResultHandler;
import com.wangshouyu.plugins.mvc.handler.ResponseBodyResultHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;

/**
 * @author 王守钰
 * @date 2020年11月20日 14:04
 * @description 统一返回结果处理配置
 */
@Configuration
@ConditionalOnProperty(value = "mvc.plugin.result-support", matchIfMissing = true)
public class ResponseBodyResultConfiguration {

    @Bean
    @ConditionalOnMissingBean(ResponseBodyResultHandler.class)
    public ResponseBodyResultHandler responseBodyResultHandler(){
        return new DefaultResponseBodyResultHandler();
    }

    @Bean
    public ResponseBodyAdvice responseBodyAdvice(){
        return new ResponseBodyResultAdvice();
    }
}
